<template>
  <div class="payable-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="8">
        <div class="summary-item">
          总计：
          <span class="summary-value">{{ (parseFloat(totalMoney)).toFixed(2) }}</span>
          元
        </div>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="16">
        <el-button
          style="z-index: 10;margin-left: 20px"
          icon="el-icon-download"
          type="success"
          :disabled="!selList.length"
          @click="importFile()"
        >
          导出
        </el-button>
        <el-form inline @submit.native.prevent>
          <el-form-item>
            <el-select
              v-model="queryForm.status"
              placeholder="全部待付"
              clearable
            >
              <el-option label="待提交" :value="1" />
              <el-option label="内审中" :value="2" />
              <el-option label="内审驳回" :value="4" />
              <el-option label="总审中" :value="3" />
              <el-option label="总审驳回" :value="5" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyword"
              placeholder="按项目、供应商、收款人、电话搜索"
              clearable
              class="search-input"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="search">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table v-loading="listLoading" :data="list" @selection-change="setSelectRow">
      <el-table-column
        header-align="center"
        type="selection"
      >
      </el-table-column>
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        type="index"
        width="95"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="supplier_alias"
        label="供应商"
        width="120"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="supplier_name"
        label="收款人"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="mobile"
        label="收款人电话"
        width="120"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="activity_name"
        label="项目名称"
        width="120"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="detail"
        label="细项"
        width="210"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="project_category"
        label="细项类别"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="number"
        label="数量"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="subtotal"
        label="小计"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="status_str"
        label="状态"
      />
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
  import { getPayableList, queryImportFile2 } from '@/api/payment'

  export default {
    name: 'Payable',

    data() {
      return {
        selList: [],
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        queryForm: {
          page: 1,
          list_row: 10,
          keyword: '',
          status: '',
        },
        totalMoney: 0,
      }
    },

    created() {
      this.getList()
    },

    activated() {
      this.getList()
    },

    methods: {
      importFile() {
        let params = {
          id: this.selList.map(val => val.id).join(',')
        }
        queryImportFile2(params).then(res => {
          location.href = res
        })
      },
      setSelectRow(val) {
        this.selList = val
      },
      async getList() {
        this.listLoading = true
        const { data, money } = await getPayableList(this.queryForm)
        this.list = data.data
        this.total = data.total
        this.totalMoney = money
        this.listLoading = false
      },
      handleSizeChange(val) {
        this.queryForm.list_row = val
        this.getList()
      },
      handleCurrentChange(val) {
        this.queryForm.page = val
        this.getList()
      },
      search() {
        this.queryForm.page = 1
        this.getList()
      },
    },
  }
</script>

<style lang="scss" scoped>
  ::v-deep .vab-query-form .left-panel {
    flex-wrap: nowrap;
  }

  .summary-item {
    display: flex;
    align-items: center;
    white-space: nowrap;
  }

  .summary-item:not(:last-child) {
    margin-right: 20px;
  }

  .summary-value {
    margin-right: 4px;
    font-size: 18px;
    font-weight: bold;
    color: #000;
  }

  .search-input {
    width: 260px;
  }
</style>
